import React from 'react';
import './index.less';
import {connect} from "dva";
import Curd from "components/Curd";
import createColumns from "./columns";
import searchColumns from "./searchColumns";
import BaseComponent from "components/Base/BaseComponent";
import {Layout, Modal} from "antd";
import UserDrpList from "./UserDrpList";

const {Content, Footer, Header} = Layout;


@connect(({drpList}) => ({drpList}))
export default class extends BaseComponent {

  state = {
    visible: false,
    userId: undefined,
  }

  getNamespace() {
    return 'drpList';
  }

  showUserDrp = (userId) =>{
    this.setState({userId, visible: true});
  }

  handleCancel = () => {
    this.setState({visible: false});
  }

  render() {

    const {visible, userId} = this.state;

    const curdProps = {
      ...this.props,
      align: 'center',
      namespace: 'drpList',
      tableColumns: createColumns,
      searchColumns: searchColumns,
      showAddDelete: false,
      showUserDrp: this.showUserDrp,
    };


    return (
      <Layout>
        {
          <Content>
            <Curd {...curdProps}/>
            <Modal
              width={800}
              title={"用户分销列表"}
              visible={visible}
              onCancel={this.handleCancel}
              footer={null}
            >
              {
                <UserDrpList userId={userId}/>
              }
            </Modal>
          </Content>
        }
      </Layout>
    );

  }

}
